rm(list = ls())
setwd('E:\\17_HuaDong\\teach\\MyLecture\\R')
library(ggplot2)
library(latex2exp)
p <- ggplot(data = data.frame(x=c(-1,1),y = c(1,2)),aes(x,y)) + geom_line() + # 下面斜线
  geom_line(data = data.frame(x=c(-1,1),y = c(2,3)),aes(x,y),linetype = 2) + #上面斜虚线
  geom_line(data = data.frame(x=c(-1,1),y = c(2,4)),aes(x,y)) + # 上面斜实线
  geom_vline(xintercept = 0) + geom_hline(yintercept = 0) + # 增加横轴和纵轴
  geom_text(data = data.frame(x=c(-1.05,1.05,-1.05,1.05,1.05,1.3,-0.5,0.5),
                              y = c(1,2,2,3,4,3.5,0.5,0.5)),aes(x,y),
            label = c("Y[t-1]^{D==0}",'Y[t]^{D==0}',"Y[t-1]^{D==1}",
                      'Y[0*t]^{D==1}',"Y[t]^{D==1}",'因果效应','T==0','T==1'),
            parse = T,size = 5) + # 增加文本标注
  geom_segment(x = 1,xend = 1,y=3,yend = 4,size =2,color = I('RoyalBlue'))+ # 增加蓝色粗实线
  geom_segment(x = 1.2,xend = 1.05,y=3.5,yend = 3.5,color = I('red'),
               arrow = arrow(length = unit(0.25,'cm')))+ # 增加红色箭头
  theme(axis.text = element_blank()) + labs(x=NULL,y=NULL) # 去掉刻度和x轴y轴标题
p
ggsave('DrawDID.png')

